home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-02-06 | 5.1 KB | 182 lines | [TEXT/MACA] |
- ( Screen invert, Mach2 and Mac+ version)
- only forth also assembler also sane
- 501504 524288 + constant screenlow ( Mac Plus)
- 5472 constant screenwords
- screenlow screenwords 4 * + constant screenhigh
-
- code i@
- move.l d6,a0
- move.l (a0),-(a6)
- rts
- end-code
- mach
-
- code i!
- move.l d6,a0
- move.l (a6)+,(a0)
- rts
- end-code
- mach
-
- code i+
- add.l d6,(a6)
- rts
- end-code
- mach
-
- code 3+
- addq.l #3,(a6)
- rts
- end-code
- mach
-
- code center
- move.l d6,a0
- move.l (a0),-(a6)
- not.l (a6)
- move.l (a6)+,(a0)
- rts
- end-code
- mach
-
- : invert screenlow
- begin dup @ not over ! 4 + dup screenhigh = until drop ;
- : test counter 50 0 do invert loop timer ;
-
- : invert2 screenhigh screenlow do i @ not i ! 4 +loop ;
- : test2 counter 50 0 do invert2 loop timer ;
-
- : invert3 screenhigh screenlow do i@ not i! 4 +loop ;
- : test3 counter 50 0 do invert3 loop timer ;
-
- : invert4 screenhigh screenlow do center 4 +loop ;
- : test4 counter 50 0 do invert4 loop timer ;
-
- ( screen inverter, definitions for MacForth, slightly altered )
- anew bench
- assembler
- 501504 524288 + constant screenlow ( Mac Plus)
- 5472 constant screenwords
- screenlow screenwords 4 * + constant screenhigh
- : SHOW.TIME ( ticks -- )
- dup cr .
- ." ticks "
- 100 60 */ <# # # ascii . hold #s #> type
- ." seconds" ;
- : counter tickcount ;
- : timer tickcount swap - show.time ;
-
- CODE bnot
- d0 get, d0 long not, d0 put, next
- END-CODE
-
- : invert1 screenlow
- begin dup @ bnot over ! 4 + dup screenhigh = until drop ;
- : test tickcount 50 0 do invert1 loop
- tickcount swap - show.time ;
-
- : invert2 screenhigh screenlow do i @ bnot i ! 4 +loop ;
- : test2 tickcount 50 0 do invert2 loop
- tickcount swap - show.time ;
-
- : invert3 screenhigh screenlow do i@ bnot i! 4 +loop ;
- : test3 tickcount 50 0 do invert3 loop
- tickcount swap - show.time ;
-
- : invert4 screenhigh screenlow
- do >CODE
- d6 a0 long move,
- d5 a0 long adda,
- a0 () long not,
- >FORTH
- 4 +loop
- ;
- : test4 tickcount
- 50 0 do invert4 loop tickcount swap - show.time ;
-
- ( Eratosthenes Sieve Benchmark, stack version )
- 8192 constant size
- variable flags size vallot ( ALLOT for MacForth Plus)
- : primes flags size 1 fill ( empty array )
- 0 ( prime counter ) size 0 ( range )
- do flags i+ c@
- if i 2* 3+ dup i+ size < ( avoid known nonprimes)
- if size flags + over i+ flags +
- do 0 i c! dup +loop ( flick mod prime flags)
- then drop 1+ ( another prime )
- then
- loop
- ;
-
- : sieve 10 0 do primes loop ;
- : sieve.demo counter sieve3 timer ;
-
- ( Eratosthenes Sieve Benchmark, local variable version )
- : prime3 { | #primes prime*2+3 limit -- }
- ( note different syntax for MF+)
- ( note also that i + should be replaced by i+ etc. in MF+ )
- flags size 1 fill
- flags size + -> limit 0 -> #primes
-
- limit 1+ flags
- do i c@
- if i flags - 2* 3 + dup -> prime*2+3
- i + limit <
- if limit 1+ prime*2+3 i +
- do 0 i c! prime*2+3 +loop ( 0ic! is one word in MF+ )
- then
- #primes 1+ -> #primes
- then
- loop
- #primes . ." primes " cr ;
-
- : sieve3 10 0 do prime3 loop ;
- : sieve3.demo counter sieve3 timer ;
-
- : million.loops
- counter 1000000 0 DO LOOP timer ;
-
- ( floating point benchmarks )
- FP
-
- : fmark1 pi 2.718281828e0 ." 10000 empty loops - "
- counter 10000 0 do fover fover fdrop fdrop loop timer
- fdrop fdrop ;
- : fmark2 pi 2.718281828e0 ." 10000 additions - "
- counter 10000 0 do fover fover f+ fdrop loop timer
- fdrop fdrop ;
- : fmark3 pi 2.718281828e0 ." 10000 subtractions - "
- counter 10000 0 do fover fover f- fdrop loop timer
- fdrop fdrop ;
- : fmark4 pi 2.718281828e0 ." 10000 multiplications - "
- counter 10000 0 do fover fover f* fdrop loop timer
- fdrop fdrop ;
- : fmark5 pi 2.718281828e0 ." 10000 divisions - "
- counter 10000 0 do fover fover f/ fdrop loop timer
- fdrop fdrop ;
- : fmark6 2.718281828e0 ." 1000 square roots - "
- counter 1000 0 do fdup fsqrt fdrop loop timer
- fdrop ;
- : fmark7 2.718281828e0 ." 1000 sines - "
- counter 1000 0 do fdup fsin fdrop loop timer
- fdrop ;
- : fmark8 2.718281828e0 ." 1000 logarithms - "
- counter 1000 0 do fdup fln fdrop loop timer
- fdrop ;
- : fmark9 2.718281828e0 ." 1000 exponentiations - "
- counter 1000 0 do fdup faln fdrop loop timer
- fdrop ;
-
- : fspeed.test cr
- fmark1 cr
- fmark2 cr
- fmark3 cr
- fmark4 cr
- fmark5 cr
- fmark6 cr
- fmark7 cr
- fmark8 cr
- fmark9 cr
- ;
-
-